define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order_install/index' + location.search,
                    add_url: 'order_install/add',
                    edit_url: 'order_install/edit',
                    del_url: 'order_install/del',
                    multi_url: 'order_install/multi',
                    import_url: 'order_install/import',
                    table: 'order_install',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'power_id', title: __('Power_id')},
                        {field: 'power_name', title: __('Power_name'), operate: 'LIKE'},
                        {field: 'package_id', title: __('Package_id')},
                        {field: 'package_name', title: __('Package_name'), operate: 'LIKE'},
                        {field: 'package_type_id', title: __('Package_type_id')},
                        {field: 'package_type_name', title: __('Package_type_name'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'extra_money', title: __('Extra_money'), operate:'BETWEEN'},
                        {field: 'order.id', title: __('Order.id')},
                        {field: 'order.type', title: __('Order.type'), operate: 'LIKE'},
                        {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},
                        {field: 'order.trade_no', title: __('Order.trade_no'), operate: 'LIKE'},
                        {field: 'order.user_id', title: __('Order.user_id')},
                        {field: 'order.province_id', title: __('Order.province_id')},
                        {field: 'order.city_id', title: __('Order.city_id')},
                        {field: 'order.area_id', title: __('Order.area_id')},
                        {field: 'order.address', title: __('Order.address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'order.mobile', title: __('Order.mobile'), operate: 'LIKE'},
                        {field: 'order.reservation_time', title: __('Order.reservation_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'order.amount', title: __('Order.amount'), operate:'BETWEEN'},
                        {field: 'order.payamount', title: __('Order.payamount'), operate:'BETWEEN'},
                        {field: 'order.paytype', title: __('Order.paytype'), operate: 'LIKE'},
                        {field: 'order.paid', title: __('Order.paid')},
                        {field: 'order.paytime', title: __('Order.paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.memo', title: __('Order.memo'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'order.createtime', title: __('Order.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.updatetime', title: __('Order.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.status', title: __('Order.status')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
